<template>
	<!-- 我的引流 -->
	<view class="mydrainage">
		<!-- 内容 -->
		<view style="padding: 30rpx;">
			<view class="itemlist" @click="detailClick(item,index)" v-for="(item,index) in newsitemlist">
				<view>
					<!-- 文本 -->
					<view class="itemText" >
						{{item.entityTitle}}
					</view>
				</view>
				<view class="itemRight">
					<view @click.stop="deleteClick(item,index)" class="rightBtn rightDelete">删除</view>
				</view>
			</view>
		</view>
		<my-empty  v-if="!newsitemlist" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
		</my-empty>
		<u-loadmore v-else :status="status" />
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/token.js'
	import {
		mapGetters
	} from 'vuex';
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	import {deletePortalNewsItem,searchPortalNewsItemList} from '@/common/api/news.js'
	export default{
		data(){
			return{
				status: 'nomore', // nomore:没有更多 loadmore:加载更多 loading:加载中
				newsitemlist:[],
				currentPage:1,
				allPage:1
			}
		},
		onLoad() {
			this.getSearchPortalNewsItemList()
		},
		onReachBottom(){
			if(this.status == 'loadmore'){
				this.currentPage++ 
				this.getSearchPortalNewsItemList()
			}
		},
		onShow: function() {
			if (this.isFresh) {
				this.getSearchPortalNewsItemList()
				this.$store.commit('isFresh', false)
			}
		},
		computed: {
			...mapGetters(['isFresh']),
		},
		methods:{
			deleteClick(item,index){
				//console.log('item',item.id)
				uni.showModal({
					title: '提示',
					content: '删除后数据不可恢复，您确定删除吗？',
					success: (e) => {
						if (e.confirm) {
							let params={}
							params['id']=item.id
							deletePortalNewsItem(params).then(res=>{
								//console.log('删除res',res)
								res = res.data
								if(res.code==200){
									if(res.data){
										uni.showToast({
											title:'删除成功！',
											icon:'none'
										})
											this.newsitemlist.splice(index,1)
											this.$store.commit('isFresh', true)
									}
								}
							})
						}
					}
				})
				
			},
			detailClick(item,index){
				//console.log('item',item)
				let newType=""
				if(item.entityName=="adbCollege"){
					newType=1
				}else if(item.entityName=="portalNews"){
					newType=2
				}
				uni.navigateTo({
					url: `/pages/newsPart/index/newsDetail?newsId=${item.entityId}`
				})
			},
			//查询引流列表
			getSearchPortalNewsItemList(){
				let params = {}
				if(getToken('version') == 1){
					params['craftsmanId'] = getToken('useNum')
				}else{
					params['companyNo'] = getToken('newsCompany')
				}
				params['entityName'] = '' //adbCollege
				params['entityId'] = ''
				params['page.current']=this.currentPage
				searchPortalNewsItemList(params).then(res=>{
					//console.log('res',res)
					res = res.data
					if(res.code=200){
						let data=res.data.records
						this.newsitemlist = duplicateRemoval(this.newsitemlist, data || [] ,'id')
						this.currentPage < res.data.pages ? this.status = 'loadmore' : this.status = 'nomore'
						//console.log('this.newsitemlist',this.newsitemlist)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.mydrainage{
		.itemlist {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: white;
			box-shadow: 0 0 10rpx 2rpx #DEE1E6;
			padding: 20rpx;
			margin-bottom: 20rpx;
		}
		.itemText {
			width: 500rpx;
			font-size: 30rpx;
			color: grey;
			white-space: normal;
			word-break: break-all;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			/* 行数 */
			-webkit-line-clamp: 3;
			overflow: hidden;
		}
		.rightBtn{
			padding: 6rpx 20rpx;
			border-radius: 10rpx;
			margin-bottom: 10rpx;
			color: white;
			font-size: 30rpx;
			font-weight: 600;
		}
		.rightDelete{
			background-color: red;
		}
	}
</style>